package user;

import types.USER_TYPE;
import database.DBHelper;

public class User {

//////////////////////////////////////////////////////////////////////////////////////////////////
// INSTANCE DATA
/////////////////////////////////////////////////////////////////////////////////////////////////

	private USER_TYPE type;
	private String username;
	private DBHelper db;
	
//////////////////////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
/////////////////////////////////////////////////////////////////////////////////////////////////
	/**
	 * Constructor
	 * @param name
	 */
	public User (String username) {
		db = new DBHelper();
		this.username = username;
		this.setType();
	}
	//------------------------------------------------------------------------------------------

	
//////////////////////////////////////////////////////////////////////////////////////////////////
// METHODS
/////////////////////////////////////////////////////////////////////////////////////////////////
	
	/**
	 * Sets the user's type
	 */
	public void setType() {
		db.open();
		db.isUserAdmin(this);
		db.isUserFaculty(this);
		db.isUserStudent(this);
		db.close();
	}
	//----------------------------------------------------------------------------------------------

	/**
	 * @return Boolean representing whether or not the user is a student
	 */
	public boolean isStudent() {
		if (type == USER_TYPE.STUDENT) 
			return true;
		else 
			return false;
	}
	//-------------------------------------------------------------------------------------------
	
	/**
	 * @return Boolean representing whether or not the user is a instructor
	 */
	public boolean isInstructor() {
		if (type == USER_TYPE.INSTRUCTOR) 
			return true;
		else 
			return false;
	}
	//-------------------------------------------------------------------------------------------
	
	/**
	 * @return Boolean representing whether or not the user is an admin
	 */
	public boolean isAdmin() {
		if (type == USER_TYPE.ADMIN) 
			return true;
		else 
			return false;
	}
	//-------------------------------------------------------------------------------------------
	
	/**
	 * @return Boolean representing whether or the user has saved his/her information
	 */
	public boolean isInformationSaved() {
		db.open();
		boolean b = db.informationIsSaved(this);
		db.close();
		return b;
	}
	//-------------------------------------------------------------------------------------------
	
	/**
	 * DEBUG METHOD
	 */
	public void dumpData() {
		System.out.println("Name: " + username + " Type: " + type);
	}
	//-------------------------------------------------------------------------------------------

	public void updateRegUser(String nameStr, String emailStr, String dobStr, String addrStr, String permAddrStr, char genderStr, String phoneStr) {
		db.open();
		db.updateRegUser(this.username, nameStr, emailStr, dobStr, addrStr, permAddrStr, genderStr, phoneStr);
		db.close();
	}
	//-------------------------------------------------------------------------------------------
	
	public void updateStudUser(String majorStr, String degreeStr) {
		db.open();
		db.updateStudUser(this.username, majorStr, degreeStr);
		db.close();
	}
	//-------------------------------------------------------------------------------------------

	public void updateInstUser(String deptStr, String positionStr, String resIntStr) {
		boolean isInfoSaved = false;
		isInfoSaved = this.isInformationSaved();
		db.open();
		db.updateInstUser(isInfoSaved, this.username, deptStr, positionStr, resIntStr);
		db.close();
	}
	//-------------------------------------------------------------------------------------------


	
//////////////////////////////////////////////////////////////////////////////////////////////////
// ACCESSORS & MUTATORS
/////////////////////////////////////////////////////////////////////////////////////////////////
	
	/**
	 * @return the name
	 */
	public String getName() {
		return username;
	}
	//-------------------------------------------------------------------------------------------

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.username = name;
	}
	//-------------------------------------------------------------------------------------------

	/**
	 * @return the type
	 */
	public USER_TYPE getType() {
		return type;
	}
	//-------------------------------------------------------------------------------------------

	/**
	 * @param type the type to set
	 */
	public void setType(USER_TYPE type) {
		this.type = type;
	}
	//-------------------------------------------------------------------------------------------

	
	
	
	
}
